<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c"%>
<%@ taglib uri="http://www.longtop.com/intelliweb" prefix="e"%>
<%@page isELIgnored="false"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>角色分配多员工</title>
</head>
<e:View id="view">
    <script type="text/javascript" src="<c:url value='/scripts/indexglobal.js'/>"></script>
	<script type="text/javascript" src="<c:url value='/scripts/skin.js'/>"></script>
    <script type="text/javascript">SkinUtil.getSkin();</script>
    <script type="text/javascript">SkinUtil.getModuleSkin();</script>
    
	<div id="Invisual Controls" style="min-height: 40px; background-color: LemonChiffon;" >
	
	<e:Dataset id="Dataset_RoleUser" datasetDefinition="DatasetDefinition.dsd" datasetRef="Dataset_RoleUser" pageSize="15" loadDataCommand="Command_Load">
		<e:Field name="id" dataType="string" label="id" maxLength="32" visible="false" />
		<e:Field name="roleId" dataType="string" label="角色ID" maxLength="32" readOnly="true" defaultValue="${param.roleId}" visible="false"/>
		<e:Field name="userId" dataType="string" label="用户ID" maxLength="32" readOnly="true"/>
		<e:Field name="userName" dataType="string" label="用户姓名" maxLength="200" required="true" dropDown="LookupDropDown_User"/>
		<e:Field name="orgName" dataType="string" label="所属机构" maxLength="200" readOnly="true"/>
		<e:Field name="homeUrl" dataType="string" label="首页定制" maxLength="100" readOnly="true" defaultValue="/welcome.jsp" visible="false"/>
	</e:Dataset>
	
	<e:Command id="Command_Search" method="search" submitForm="true" action="com.longtop.framework.sys.role.web.RoleUserAction" showHintInfoOnSuccess="false">
		<e:DatasetInfo name="info1" dataset="Dataset_RoleUser" alwayRefreshClient="true" submitType="none"></e:DatasetInfo>
		<e:Parameter name="roleId" value="${param.roleId}"></e:Parameter>
	</e:Command>
	<e:Command id="Command_Load" method="load" submitForm="true" action="com.longtop.framework.sys.role.web.RoleUserAction" showHintInfoOnSuccess="false">
		<e:DatasetInfo name="info1" dataset="Dataset_RoleUser" alwayRefreshClient="true" submitType="none"></e:DatasetInfo>
		<e:Parameter name="roleId" value="${param.roleId}"></e:Parameter>
	</e:Command>
	
	<e:Command id="Command_Save" action="com.longtop.framework.sys.role.web.RoleUserAction" method="save" onExecuteSuccess="Command_Save_onExecuteSuccess(command)">
		<e:DatasetInfo name="info1" dataset="Dataset_RoleUser" submitType="changes" ></e:DatasetInfo>
	</e:Command>
	
	<e:LookupDropDown id="LookupDropDown_User" path="/jsp/framework/sys/user/userDropdown.jsp" windowWidth="650" windowHeight="450" 
			autoDropDown="true" fixed="true" onSelect="LookupDropDown_User_onSelect(dropdown,iframe,text)" windowCaption="选择员工">
	</e:LookupDropDown>	
</div>
	
<body>
	<e:Page id="ePage" action="com.longtop.framework.sys.role.web.RoleUserAction" style="min-height: 80px; width: 100%; height: 100%;" onAfterLoadPage="ePage_onAfterLoadPage()">
		<table style="width: 100%; height: 100%;" border="0" cellpadding="2" cellspacing="2" width="100%">
			<tr>
				<td width="100%" height="90%" align="left" valign="top">
					<e:Panel id="Panel_RoleUser" style="width: 100%; height: 100%" caption="用户信息" captionIcon="/images/list_win.gif"
						captionStyle="color:#888888" allowFold="false" showArrowButton="false">
							<table style="text-align: left; width: 100%;" border="0" cellpadding="2" cellspacing="2" width="100%" align="center">
								<tr>
									<td>
										<table style="text-align: left;" border="0" cellpadding="0" width="100%" cellspacing="0">
											<tr>
												<td  height="27px" width="1%" nowrap="nowrap">
													<e:RecordNavigator id="RecordNavigator_Role" dataset="Dataset_RoleUser" style="width: 0px" showNavigatorButton="false">
														<e:RecordButton id="RecordButton_insert" label="新增员工" onClick="RecordButton_insert_Onclick()" icon="/images/add.gif"></e:RecordButton>
														<e:RecordButton id="RecordButton_delete" label="删除" onClick="deleteRecord" icon="/images/delete.gif"></e:RecordButton>
														<e:RecordButton id="RecordButton_submit" label="提交保存" onClick="RecordButton_submit_onClick()" icon="/images/save.gif"></e:RecordButton>
													</e:RecordNavigator>
												</td>
												<td  align="left" width="99%"><e:PageNavigator id="PageNavigator_Role" dataset="Dataset_RoleUser" style="min-width: 200px; height: 25px;;"></e:PageNavigator></td>
											<tr>
										</table>
									</td>	
								</tr>
								<tr>
									<td>
										<e:Grid id="Grid_Result" style="width: 100%; height: 450px;"	dataset="Dataset_RoleUser" showFilterRow="false" showIndicator="true" showIndex="true">
										</e:Grid>
									</td>
								</tr>
							</table>
					</e:Panel>
				</td>
			</tr>
		</table>
	</e:Page>
</body>

<script type="text/javascript">

	//init
	function ePage_onAfterLoadPage(){
		$J("Panel_RoleUser").setCaption("角色："+Util.decode("${param.roleName}")+"【${param.roleId}】 — 用户分配详细");
	}
	
	//添加分配员工
	function RecordButton_insert_Onclick(){
		function isRecordExist(userId){		//判断员工记录是否已经存在：
			var record = Dataset_RoleUser.getFirstRecord();
			var flag =false;
			while(record){
				if(record.getValue("userId") == userId){
					flag = true;
					break;
				}
				record = record.getNextRecord();			
			}
			return flag;		
		}	
		
		var arrayMap = selectUsersFromWindow();//选择员工弹出框
		if(arrayMap == ''){
			return;
		}
		
		Dataset_RoleUser.disableControls();	
		try {			
			for (var i =0 ; i<arrayMap.length ; i++){
				var userId = arrayMap[i].get("userId");
				if(isRecordExist(userId)){
					continue;
				}
	 			var newRecord = Dataset_RoleUser.insertRecord(false);
				newRecord.setValue("userId",userId);
				newRecord.setValue("userName",arrayMap[i].get("userName"));
				newRecord.setValue("orgName",arrayMap[i].get("orgName"));
			}	
		}finally {
			Dataset_RoleUser.enableControls();
			Dataset_RoleUser.refreshControls();
		}					
	}
	
	//保存
	function RecordButton_submit_onClick(){
		var flag = Command_Save.execute();
		
		reloadWin = function(){
			window.location.reload();
		}
		
		if(flag){
			var msg=Command_Save.getResponseMessage();
			MsgBox.showInfoMsg(msg,"",[reloadWin]);
		}
	}
	
	//返回
	function Button_Back_onClick(){
		var tabName = "<%=request.getParameter("openerTabName") %>";
		returnToParentTab(tabName,true);
	}	

	//选择User(处理dataset的值) 
	function LookupDropDown_User_onSelect(dropdown,iframe,text){
		
		var userDataset = $J(iframe.Dataset_User);
	   	if(userDataset){
	    	var record = userDataset.getCurrentRecord();
	    	if(typeof record != "undefined" && record != null){
	       		Dataset_RoleUser.setValue("userId",record.getValue("userId"));
	   			Dataset_RoleUser.setValue("userName",record.getValue("userName"));
	   			Dataset_RoleUser.setValue("orgName",record.getValue("orgName"));
	    	}
		}		
	}

</script>
</e:View>
</html>